<template>
    <div class="container">
        <div class="handle-box">
                <el-form ref="form" :model="form" label-width="90px" class="flex">
                    <el-form-item label="区域名称：">
                        <el-input v-model="name" placeholder="请输入名称" class="handle-input mr10" @input="mohu()"></el-input>
                    </el-form-item>
                    <!-- <el-form-item label="日期范围：">
                       <el-date-picker
                            v-model="value1"
                            type="daterange"
                            range-separator="至"
                            start-placeholder="开始日期"
                            end-placeholder="结束日期">
                        </el-date-picker>
                    </el-form-item> -->
                    <el-form-item>
                        <el-button type="primary" icon="el-icon-search" @click="search">搜索</el-button>
                        <!-- <el-button type="success" icon="el-icon-circle-plus-outline" @click="addvialog()">新增</el-button> -->
                    </el-form-item>
                    
                </el-form>
            </div>
            <el-table
                :data="tableData.slice((currentPage-1)*pagesize,currentPage*pagesize)"
            >
                <el-table-column prop="STREET_ID" label="ID" width="55" align="center"></el-table-column>
                <el-table-column prop="STREET_NAME" label="区域名称"></el-table-column>
                <el-table-column  label="累计积分">
                    <template scope="scope">
                        <div class="u" @click="getMore(scope.row)">{{ scope.row.TotalPoints }}</div>
                    </template>
                </el-table-column>
                <el-table-column  label="消费积分">
                    <template scope="scope">
                        <div class="u" @click="getscoreMore(scope.row)">{{ scope.row.ConsumePoints }}</div>
                    </template>
                </el-table-column>
                <el-table-column prop="SurplusPoints" label="剩余积分"></el-table-column>
            </el-table>
            <div class="pagination">
                <el-pagination
                    background
                    layout="total, sizes, prev, pager, next, jumper"
                    :current-page="currentPage"  
                    :page-size="pageSize"
                    :total="tableData.length"
                    @size-change="handleSizeChange"
                    @current-change="handlePageChange"
                ></el-pagination>
            </div>
            <!-- 编辑弹出框 -->
            <el-dialog v-dialogDrag title="信息" :visible.sync="editVisible" width="50%" >
                <el-form ref="form" :model="form" label-width="70px" class="diaglos display">
                    <el-form-item label="街道名称：" :label-width="formLabelWidth" class="wid50">
                        <input v-model="form.address" class="inputstyle" type="text" disabled="disabled"></input>
                    </el-form-item>
                    <el-form-item label="日期范围：" :label-width="formLabelWidth" class="wid50">
                        <input v-model="form.date" class="inputstyle" type="text" disabled="disabled"></input>
                    </el-form-item>
                    <el-form-item label="可回收垃圾累计积分：" :label-width="formLabelWidth" class="wid50">
                        <input v-model="form.integral" class="inputstyle" type="text" disabled="disabled"></input>
                    </el-form-item>
                    <el-form-item label="厨余垃圾累计积分：" :label-width="formLabelWidth" class="wid50">
                        <input v-model="form.chuyuintegral" class="inputstyle" type="text" disabled="disabled"></input>
                    </el-form-item>
                    <el-form-item label="有害垃圾累计积分：" :label-width="formLabelWidth" class="wid50">
                        <input v-model="form.youhaiintegral" class="inputstyle" type="text" disabled="disabled"></input>
                    </el-form-item> 
                    <el-form-item label="其他垃圾累计积分：" :label-width="formLabelWidth" class="wid50">
                        <input v-model="form.qitaintegral" class="inputstyle" type="text" disabled="disabled"></input>
                    </el-form-item> 
                </el-form>
                <span slot="footer" class="dialog-footer">
                    <el-button @click="editVisible = false">取 消</el-button>
                    <el-button type="primary" @click="saveEdit">确 定</el-button>
                </span>
            </el-dialog>

              <!-- 积分明细弹出框 -->
            <el-dialog title="积分明细" :visible.sync="detaildialog" width="30%" >
                <div class="block scrolly" style="height:300px;">
                    <el-timeline >
                      <el-timeline-item 
                        v-for="(activity,index) in avtives"
                        :key='index'
                        :size='activity.size'
                        :color='activity.color'
                        :timestamp="activity.data" 
                        placement="top"
                        >
                        <el-card style="border:2px solid #cecece">
                          <h4>{{activity.content}}</h4>
                          <p>{{activity.name}} 提交于 {{activity.timestamp}}</p>
                        </el-card>
                      </el-timeline-item>
                    </el-timeline>
                </div>
                 <span slot="footer" class="dialog-footer">
                    <el-button @click="detaildialog = false">取 消</el-button>
                    <!-- <el-button type="primary" @click="saveEdit">确 定</el-button> -->
                </span>
            </el-dialog>
            <!-- 累计积分明细 -->
             <el-dialog v-dialogDrag title="累计积分明细" :visible.sync="getmoredialog" width="50%" >
                <el-table :data="communitydetaildata">
                    <!-- <el-table-column prop="COMMUNITY_ID" label="社区ID"  align="center"></el-table-column> -->
                    <el-table-column prop="STREET_NAME" label="街道名称"></el-table-column>
                    <el-table-column prop="TotalPoints" label="全部积分"></el-table-column>
                    <!-- <el-table-column prop="ConsumePoints" label="消费积分"></el-table-column> -->
                    <!-- <el-table-column prop="SurplusPoints" label="剩余积分"></el-table-column> -->
                </el-table>
            </el-dialog>
            <!-- 消费积分明细 -->
             <el-dialog v-dialogDrag title="消费积分明细" :visible.sync="getscoremoredialog" width="50%" >
                 <el-table :data="communityildata">
                    <!-- <el-table-column prop="COMMUNITY_ID" label="社区ID"  align="center"></el-table-column> -->
                    <el-table-column prop="STREET_NAME" label="街道名称"></el-table-column>
                    <el-table-column prop="ConsumePoints" label="消费积分"></el-table-column>
                </el-table>
            </el-dialog>
            <!-- 新增弹出框 -->
             <el-dialog v-dialogDrag title="新增" :visible.sync="adddatevialog" width="50%" >
                 <el-form ref="addform" :model="addform" label-width="70px" class="diaglos display">
                    <el-form-item label="街道名称：" :label-width="formLabelWidth" class="wid50">
                        <el-input v-model="addform.address" ></el-input>
                    </el-form-item>
                    <el-form-item label="街道累计积分：" :label-width="formLabelWidth" class="wid50">
                        <el-input v-model="addform.totalintegral"></el-input>
                    </el-form-item>
                    <el-form-item label="街道消费积分：" :label-width="formLabelWidth" class="wid50">
                        <el-input v-model="addform.totalscore"></el-input>
                    </el-form-item>
                    <el-form-item label="街道剩余积分：" :label-width="formLabelWidth" class="wid50">
                        <el-input v-model="addform.totalremaining"></el-input>
                    </el-form-item> 
                </el-form>
                <span slot="footer" class="dialog-footer">
                    <el-button @click="adddatevialog = false">取 消</el-button>
                    <el-button type="primary" @click="saveEditvialog">确 定</el-button>
                </span>
            </el-dialog>
        </div>
</template>
<script>
import '../../../assets/css/common.css'
import consumptionintegralVue from '../consumptionintegral.vue';

export default {
    data(){
        return{
              currentPage:1, //初始页
                pagesize:10,    //    每页的数据
                userList: [],
                address:'',
                name:'',
                value1: '',
                search: '',
                streetname:'',
                detaildialog:false,
                getmoredialog:false,    //累计积分明细
                getscoremoredialog:false,   //消费积分明细
                addform:{
                },
            tableData: [{
                STREET_ID: '1',
                STREET_NAME: '富民路',
                ConsumePoints: '50', //消费
                TotalPoints: '200', //累计
                SurplusPoints: '150', //剩余
            },{
                STREET_ID: '2',
                STREET_NAME: '二号桥',
                ConsumePoints: '50', //消费
                TotalPoints: '230', //累计
                SurplusPoints: '180', //剩余
            },{
                STREET_ID: '3',
                STREET_NAME: '东新',
                ConsumePoints: '10', //消费
                TotalPoints: '350', //累计
                SurplusPoints: '340', //剩余
            },{
                STREET_ID: '4',
                STREET_NAME: '向阳楼',
                ConsumePoints: '10', //消费
                TotalPoints: '350', //累计
                SurplusPoints: '340', //剩余
            },{
                STREET_ID: '5',
                STREET_NAME: '春华街道',
                ConsumePoints: '100', //消费
                TotalPoints: '350', //累计
                SurplusPoints: '250', //剩余
            },{
                STREET_ID: '6',
                STREET_NAME: '中山门街道',
                ConsumePoints: '92', //消费
                TotalPoints: '500', //累计
                SurplusPoints: '408', //剩余
            },{
                STREET_ID: '7',
                STREET_NAME: '南市街道',
                ConsumePoints: '150', //消费
                TotalPoints: '1000', //累计
                SurplusPoints: '850', //剩余
            },{
                STREET_ID: '8',
                STREET_NAME: '劝业场街道',
                ConsumePoints: '110', //消费
                TotalPoints: '350', //累计
                SurplusPoints: '240', //剩余
            }],
            multipleSelection: [],
            delList: [],
            editVisible: false,
            pageTotal: 0,
            form: {},
            idx: -1,
            id: -1,
            formLabelWidth:'160px',
            communitydetail:[{
                index:'1',
                communname:[]
            },{
                index:'2',
               communname:[]              
            },{
                index:'3',
               communname:[]            
            },{
                index:'4',
                communname:[]               
            },{
                index:'5',
               communname:[]              
            },{
                index:'6',
                communname:[]               
            },{
                index: '7',
                communname:[]               
            },{
                index:'8',
                communname:[]                
            }],
            communitydetaildata:'', 
            communityildata: '',
            adddatevialog:false,
            addform:''
        }
    },
    created() {
        this.getdata();
    },
    methods: {
        // async getdata(){
        //     const { data } =await this.$axios.get(this.$iurl+'/GetStreetIntegralListApi')
        //     this.tableData = data.filter(item=>{
        //         return item 
        //     })
        // },
        getdata() {
            this.$axios({
                url: this.$iurl + '/GetStreetIntegralListApi',
                method: 'get',
                params: {
                   ClientNo: localStorage.getItem('clentno')
                }
            }).then(res=>{
                // this.communitydetaildata = Object.assign([],res.data)
                // console.log(res.data)
                var sumIntegral = 0;
                var consumeIntegral = 0;
                res.data.forEach(element => {
                    sumIntegral += element.TotalPoints
                    consumeIntegral += element.ConsumePoints
                });
                this.tableData = [{"STREET_ID":1,"STREET_NAME":"东丽区","TotalPoints":sumIntegral,"ConsumePoints":consumeIntegral,"SurplusPoints":(sumIntegral-consumeIntegral)}]
            })
            },
        async saveEditvialog(){
            this.adddatevialog = false
        },
        //新增弹出框
        async addvialog(){
            this.adddatevialog = true
        },
        //累计积分弹框
        getMore(row){
            this.$axios({
                url: this.$iurl + '/GetStreetIntegralListApi',
                method: 'get',
                params: {
                   ClientNo: localStorage.getItem('clentno')
                }
            }).then(res=>{
                this.communitydetaildata = Object.assign([],res.data)
                // console.log(res.data)
            })
            // [{"STREET_ID":1,"STREET_NAME":"盖山镇","TotalPoints":398383.6,"ConsumePoints":30.0,"SurplusPoints":398383.6}]
            // this.communitydetaildata = [{"COMMUNITY_ID":1,"COMMUNITY_NAME":"盖山镇","Points":398383.6}]
            this.getmoredialog = true
            // console.log(row);
        },
         //消费积分弹框
        async getscoreMore(row){
            this.$axios({
                url: this.$iurl + '/GetStreetIntegralListApi',
                method: 'get',
                params: {
                   ClientNo: localStorage.getItem('clentno')
                }
            }).then(res=>{
                this.communityildata = Object.assign([],res.data)
                // console.log(res.data)
            })
            this.getscoremoredialog = true
        },
        // 积分明细弹框
        async detail(index,row){
            console.log(index,row)
            this.detaildialog = true;
        },
        // 模糊搜索
         mohu() {
            var search = this.name;
            var newdate = [];
            if(search){
                this.tableData.filter(item => {
                    console.log(item)
                    if(item.STREET_NAME.indexOf(search) != -1){
                        newdate.push(item)
                    }
                })
            }else{ 
                this.getdata()
            }
            this.tableData = newdate
        },
        // 搜索
        search(){
            var search = this.name;
            var newdate = [];
            if(search){
                this.tableData.filter(item => {
                    console.log(item)
                    if(item.STREET_NAME.indexOf(search) != -1){
                        newdate.push(item)
                    }
                })
            }else{ 
                this.getdata()
            }
            this.tableData = newdate
        },
        // 编辑操作
        handleEdit(index, row) {
            this.idx = index;
            this.form = row;
            this.editVisible = true;
        },
        // 保存编辑
        saveEdit(addform) {
            // this.editVisible = false;
            // this.$message.success(`修改第 ${this.idx + 1} 行成功`);
            // this.$set(this.tableData, this.idx, this.form);
        },
        // 分页导航
        handlePageChange(currentPage) {
            this.currentPage = currentPage;
            console.log(this.currentPage)
            // this.$set(this.query, 'pageIndex', val);
            // this.getData();
        },
        handleSizeChange(size){
            this.pagesize = size;
            console.log(this.pagesize)
        }
    }
}
</script>
<style scoped>
    .el-form-item__label{
        width: 140px!important;
    }
    .table{
        border-collapse: collapse;
        border-spacing: 0;
        text-align:center;
        empty-cells: show;
        border: 1px solid #cbcbcb;
    }
    .table thead{
        background-color: #e0e0e0;
        border-bottom: 1px solid #cbcbcb;
        font-weight: 600;
    }
    .table tbody tr{
        border-bottom: 1px solid #cbcbcb;
    }
    .table td{
        padding:5px 0;
        border-left: 1px solid #cbcbcb;
        border-bottom: 1px solid #cbcbcb;
        border-width: 0 0 0 1px;
    }
</style>